# vim: filetype=sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.

. $STF_SUITE/include/libtest.kshlib

# 
# check if the <pool> contains <vdev> ...
#
# $1 pool 
# $2..n <vdev> ...
#
# Return 0 if <vdev> are contained in the <pool>; 1 if not used; 2 if pool
# name is missing
#
function iscontained
{
	typeset pool=$1
	typeset vdev

        if [[ -z $pool ]]; then
                log_note "Missing pool name."
                return 2
        fi

	shift

	for vdev in $@; do

# remove /dev/ in vdev if there is
		vdev=${vdev#/dev/}

		$ZPOOL status "$pool" | $AWK '$1 == vdevname {exit 1}' \
			vdevname=$vdev >/dev/null 2>&1
		(( $? != 1 )) && \
			return 1
	done

	return 0;

}

#
# Common cleanup routine for partitions used in testing
#
function partition_cleanup
{
	log_note "Cleaning up partitions..."
	if [[ -n $DISK ]]; then
		partition_disk $SIZE $DISK 7
	else
		typeset disk=""
		for disk in $DISK0 $DISK1; do
			partition_disk $SIZE $disk 7
		done
	fi
}
